//
//  CourseClassAlertView.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/1.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "CourseClassAlertView.h"

@implementation CourseClassAlertView

-(id)initWithFrame:(CGRect)frame{
    
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
        
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.4];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"选择课程种类";
        titleLabel.font = BoldBigFont;
        [whiteView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIButton *closeBtn = [[UIButton alloc] init];
        [closeBtn setImage:@"pop_icon_close"];
        [closeBtn addTarget:self action:@selector(hiddenWithAnimation)];
        [whiteView addSubview:closeBtn];
        self.closeBtn = closeBtn;
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LineBackGroundColor;
        [whiteView addSubview:lineView];
        self.lineView = lineView;
     
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"img-nolesson"];
        [whiteView addSubview:imageView];
        self.imageView = imageView;
        
        /**
         提示
         */
        UILabel *noticeLabel = [[UILabel alloc] init];
        noticeLabel.text = @"暂无课程种类";
        noticeLabel.font = BigFont;
        noticeLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [whiteView addSubview:noticeLabel];
        self.noticeLabel = noticeLabel;
        
        /**
         提示
         */
        UILabel *noticeLabel1 = [[UILabel alloc] init];
        noticeLabel1.text = @"请前往添加课程种类";
        noticeLabel1.font = [UIFont systemFontOfSize:13.0];
        noticeLabel1.textColor = CSColorFromRGB(0x999999);
        [whiteView addSubview:noticeLabel1];
        self.noticeLabel1 = noticeLabel1;
        
        /**
         添加按钮
         */
        UIButton *addBtn = [[UIButton alloc] init];
        addBtn.layer.cornerRadius = 2;
        addBtn.layer.masksToBounds = YES;
        addBtn.backgroundColor = ButtonBackGroundColor;
        [addBtn setTitle:@"添加场馆"];
        [addBtn setImage:@"icon_addbtn"];
        [addBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        addBtn.titleLabel.font = BigFont;
        [whiteView addSubview:addBtn];
        self.addBtn = addBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self);
    }];
    
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(20);
        make.right.mas_equalTo(self).offset(-20);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.whiteView).offset(20);
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.whiteView).offset(-10);
        make.top.mas_equalTo(self.whiteView).offset(10);
    }];
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(30);
        make.left.width.mas_equalTo(self.whiteView);
        make.height.mas_equalTo(1);
    }];
    
    [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(10);
        
        make.centerX.mas_equalTo(self.whiteView);
        
    }];
    
    [self.noticeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.imageView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.noticeLabel1 mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.noticeLabel.mas_bottom).offset(10);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.noticeLabel1.mas_bottom).offset(20);
        
        make.left.mas_equalTo(self.whiteView).offset(20);
        
        make.right.mas_equalTo(self.whiteView).offset(-20);
        
        make.bottom.mas_equalTo(self.whiteView).offset(-20);
        
        make.height.mas_equalTo(50);
    }];
}

-(void)hiddenWithAnimation{
    
    CGFloat height = self.whiteView.frame.size.height;
    
    [UIView animateWithDuration:0.25 animations:^{
        
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
        
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
        
    } completion:^(BOOL finished) {
        
        [self removeFromSuperview];
    }];
}
@end
